package fr.mywiki.business.navigation;

import fr.mywiki.business.navigation.NavigationManager;
import fr.mywiki.business.navigation.SpaceFlyweight;
import fr.mywiki.business.navigation.SpacesList;
import fr.mywiki.business.profil.Profile;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Test class for SpacesList class
 * 
 * @see http://localhost:8080/MyWiki/ServletTestRunner?suite=fr.mywiki.business.manager.navigation.SpacesListTest&xsl=cactus-report.xsl
 */
public class SpacesListTest extends TestCase {
	public SpacesListTest(String a_name) {
		super(a_name);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite();
		suite.addTestSuite(SpacesListTest.class);

		return suite;
	}
	
	/** Testing the class constructor */
	public void testConstructors() {
		SpacesList spaces = new SpacesList();
		assertTrue(spaces.getSpaces().isEmpty());
	}
	
	/** Testing containsSpace() method */
	public void testContainsSpace() {
		SpacesList spaces = SpacesList.getSpacesList(Profile.AUTHOR_PROFILE_ID);
		
		assertTrue(spaces.containsSpace(NavigationManager.WIKI_SPACE));
		assertFalse(spaces.containsSpace(NavigationManager.ADMIN_SPACE));
	}
	
	/** Tests getSpace(int) method */
	public void testGetSpace() {
		SpacesList spaces = SpacesList.getSpacesList(Profile.ADMIN_PROFILE_ID);
		
		SpaceFlyweight space = spaces.getSpace(0);
		assertEquals(NavigationManager.WIKI_SPACE,space.getName());
		assertEquals("Wiki",space.getTitle());
		assertEquals(NavigationManager.WIKI_SPACE,space.getStartForward());
		
		space = spaces.getSpace(1);
		assertEquals(NavigationManager.ADMIN_SPACE,space.getName());
		assertEquals("Administration",space.getTitle());
		assertEquals(NavigationManager.ADMIN_SPACE,space.getStartForward());

	}
	
	/** Testing getSpaceName(int) method */
	public void testGetSpaceName() {
		SpacesList spaces = SpacesList.getSpacesList(Profile.ADMIN_PROFILE_ID);
		
		assertEquals(NavigationManager.WIKI_SPACE,spaces.getSpaceName(0));
		assertEquals(NavigationManager.ADMIN_SPACE,spaces.getSpaceName(1));
	}
	
	/** Testing putSpace(SpaceFlyweight) method */
	public void testPutSpace() {
		SpacesList spaces = SpacesList.getSpacesList(Profile.AUTHOR_PROFILE_ID);
		
		SpaceFlyweight space = new SpaceFlyweight("to be found","to be found", "to be found");
		spaces.put(space);
		assertEquals(space,spaces.getSpace(1));
	}
}
